package com.qidian.buy.controller;

import com.qidian.buy.entity.Item;
import com.qidian.buy.entity.ItemDesc;
import com.qidian.buy.service.IItemService;
import com.qidian.buy.util.pojo.LayuiTableDTO;
import com.qidian.buy.util.pojo.QDResult;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Author 郭浩
 */
@RestController
@RequestMapping("/item")
@CrossOrigin
public class ItemController {
    @Resource
    private IItemService itemService;

    @RequestMapping("/save")
    public QDResult save(Item item){
        ItemDesc itemDesc = item.getItemDesc();
        return itemService.save(item,itemDesc);
    }

    @RequestMapping("/edit")
    public QDResult edit(Item item){
        return itemService.edit(item);
    }

    @RequestMapping("/delete")
    public QDResult delete(Item item){
        return itemService.delete(item);
    }

    @RequestMapping("/get")
    public QDResult get(Long itemId){
        return itemService.get(itemId);
    }

    @RequestMapping("/query")
    public LayuiTableDTO<Item> query(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10")int limit, Item item){
        return itemService.query(page, limit, item);
    }
    @RequestMapping("/search")
    public QDResult search(Item item ,@RequestParam(defaultValue = "1") int page,@RequestParam(defaultValue = "10")int limit){
        return  itemService.search(item,page,limit);
    }
}
